/**
 * \* Created with IntelliJ IDEA.
 * \* User: 冯若航
 * \* Date: 2021/5/23
 * \* Time: 10:36
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class 哪种连续子字符串更长 {
    public boolean checkZeroOnes(String s) {
        //1的长度
        int l1=0;
        //0的长度
        int l0=0;

        int l=0;
        int flag=0;
        char[] str=s.toCharArray();
        for(Character c:str){
            if(c=='1'&&flag==0){
                l=1;
                flag=1;
                l1=Math.max(l1,l);
            }else if(c=='1'&&flag==1){
                l++;
                l1=Math.max(l1,l);
            }else if(c!='1'){
                flag=0;
                l1=Math.max(l1,l);
                l=0;
            }
        }

        l=0;
        for(Character c:str){
            if(c=='0'&&flag==0){
                l=1;
                flag=1;
                l0=Math.max(l0,l);
            }else if(c=='0'&&flag==1){
                l++;
                l0=Math.max(l0,l);
            }else if(c!='0'){
                flag=0;
                l0=Math.max(l0,l);
                l=0;
            }
        }
        if(l1>l0){
            return true;
        }else {
            return false;
        }
    }
}